package com.gcxy.conf.exception.handler;


import com.gcxy.conf.exception.annotation.GlobalException;
import com.gcxy.conf.exception.exception.IGlobalException;
import com.gcxy.conf.result.R;
import com.gcxy.conf.result.ResultCodeEnum;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 非法状态异常
 * IllegalStateException：表示某个方法在非法或不适当的时间被调用的信号
 * 即当前对客户端的响应已经结束，不能在响应已经结束（或说消亡）后再向客户端（实际上是缓冲区）输出任何内容
 *
 * @author shineTan
 * @date 2022/12/26 14:42
 */
@GlobalException(throwable = IllegalStateException.class)
public class IllegalStateExceptionHandler implements IGlobalException<R, IllegalStateException> {

    @Override
    public R exception(IllegalStateException throwable, HttpServletRequest request, HttpServletResponse response) {
        return R.Failed(ResultCodeEnum.TOKEN_EXPIRED_REDIRECT.getCode(), ResultCodeEnum.TOKEN_EXPIRED_REDIRECT.getMessage());
    }
}
